﻿using System;
using System.Web;

namespace Toolkit.Web.Infastructure
{
    public abstract class ViewComponentHtmlBuilderBase
    {
        protected ViewComponentHtmlBuilderBase(ViewComponentBase component)
        {
            if (component == null)
            {
                throw new ArgumentNullException("component");
            }

            Component = component;
        }

        protected ViewComponentBase Component
        {
            get;
            private set;
        }

        public abstract IHtmlNode Html();

        public virtual void ApplyComponentIdentifierAttribute(IHtmlNode htmlNode)
        {
            if (Component.Identifier != null)
            {
                htmlNode.Attributes["data-vc-id"] = HttpUtility.HtmlAttributeEncode(Component.Identifier);
            }
        }
    }
}
